<?php
/**
 * Created by PhpStorm.
 * User: xrr
 * Date: 18-8-31
 * Time: 下午8:43
 */
if (! function_exists('api_response')) {
    /**
     * Return a new api response from the application.
     *
     * @param  string   $err
     * @param  array    $data
     * @param  string   $errMsg
     * @param  int      $status
     * @param  array    $headers
     * @param  int      $options
     * @return \Illuminate\Http\Response
     */
    function api_response($errName = '', array $data = [], $errMsg = null, $status = 200, array $headers = [], $options = 0)
    {
        $errName = $errName ?: 'ok';
        $error   = config("error.{$errName}", []);
        return response()->json([
            'code'    => array_get($error, 'code', 200),
            'message' => is_null($errMsg) ? array_get($error, 'message', '操作成功') : $errMsg,
            'data'    => $data,
        ], $status, $headers, $options);
    }
}

if(!function_exists('join_time')){
    function join_time($time)
    {
        if(is_array($time)){
            $firstTime=substr($time[0],0,5);
            $lastTime=substr($time[count($time)-1],-5);
            $time=$firstTime.'-'.$lastTime;
        }
        return $time;

    }
}